package mts.gui;

import mts.ElevatorControllerInternalConnectionServer;
import mts.common.CommonSettings;
import mts.groupdispatcher.GroupDispatcher;
import mts.groupdispatcher.GroupDispatcherConnectionServer;
import mts.strategies.AdvancedStrategy;
import mts.strategies.SimpleStrategy;

import org.apache.log4j.BasicConfigurator;

public class GuiInitializer {

	public static void main(String args[]) {
		setupLog4J();
		
		int groupDispatcherPort = CommonSettings.DEFAULT_SERVER_PORT;
		int guiPort = CommonSettings.DEFAULT_INTERNAL_CONNECTION_SERVER_PORT;
		if (args.length == 1) {
			groupDispatcherPort = Integer.parseInt(args[0]);
		}		
		
		MainGui controllerManager = new MainGui();
		
		GroupDispatcher groupDispatcher = new GroupDispatcher(controllerManager, new AdvancedStrategy());
		GroupDispatcherConnectionServer connectionServer = new GroupDispatcherConnectionServer(groupDispatcher, groupDispatcherPort);		
		connectionServer.start();
		
		
		ElevatorControllerInternalConnectionServer guiConnectionServer = new ElevatorControllerInternalConnectionServer(guiPort, controllerManager);
		controllerManager.setInternalConnectionServer(guiConnectionServer);
		guiConnectionServer.start();
		
	}

	private static void setupLog4J() {
		BasicConfigurator.configure();
		//PropertyConfigurator.configure("log4j.properties");
	}
}
